import React, { Component } from 'react';
import { base, ajax, formDownload, toast } from "nc-lightapp-front";
import { REQUEST_URL } from '../../constant';
import { cardRefresh } from '../../card/events/cardOperator';
import { listRefresh } from '../../list/events/listOperator';
const {NCModal, NCButton, NCTree, NCTextArea} = base;
const {Header: ModalHeader, Body: ModalBody, Footer: ModalFooter} = NCModal;

class BohuiModel extends Component {

    constructor(props) {
        super(props);
        this.state = {
            showModal: false,
            retObj:''
          };
        this.onClose = this.onClose.bind(this);
    }

    onClose() {
        this.props.updateState({
            bohuiModelVisiable: false
        });
    }

    onChange(value) {
        
    }

    onBlur(value){
        this.state.retObj = value;
    }

    onOk(refObj){
        if(this.state.retObj == ''){
            toast({content:'驳回批语不能为空' ,color:'danger'});
        }else{
            this.props.updateState({
                bohuiModelVisiable: false
            });

            let data = {
                action:'BACKAPPROVE',
                pks: this.props.bohuiIDs,
                message:this.state.retObj
            }

            if(this.props.bohuiFrom === 'LIST'){
                ajax({
                    url: REQUEST_URL.workflow,
                    data: data,
                    success: (res) => {
                        toast({
                            color: "success",
                            title: '提示',
                            content: "操作成功",
                            TextArr: ['展开', '收起', '关闭'],/* 国际化处理： 展开,收起,关闭*/
                            groupOperation: true
                        });
            
                        listRefresh(this.props);
                    }
                });
            }else{
                ajax({
                    url: REQUEST_URL.workflow,
                    data: data,
                    success: (res) => {
                        toast({
                            color: "success",
                            title: '提示',
                            content: "操作成功",
                            TextArr: ['展开', '收起', '关闭'],/* 国际化处理： 展开,收起,关闭*/
                            groupOperation: true
                        });
            
                        cardRefresh(this.props);
                    }
                });
            }
            
        }
    }

    render () {

        const { bohuiModelVisiable, retObj, bohuiIDs, bohuiFrom} = this.props;

        return (
            <div>
                <NCModal
                    show = {bohuiModelVisiable}
                    onHide={this.onClose}
                    //  bodyStyle={{ height: '700px' }}
                    >
                    <ModalHeader closeButton={true} draggable={true}>
                        <span>绩效系数生成</span>
                    </ModalHeader>
                    <ModalBody style={{ textAlign: 'center' }}>
                    <div style={{ width: 360, display: 'inline-block' }}>
                        <NCTextArea  onChange={this.onChange.bind(this)} onBlur={this.onBlur.bind(this)}/>
                    </div>

                    </ModalBody>
                    <ModalFooter>
                        <NCButton colors="primary" onClick={this.onOk.bind(this, retObj)}>确认</NCButton>
                        <NCButton onClick={this.onClose}>取消</NCButton>
                    </ModalFooter>
                </NCModal>


            </div>
        )
    }
}

export default BohuiModel;